<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>属性函数</title>
    <!--    将::after的opacity设置0，然后:hover::afters的opacity设置为1-->
    <style>
        h1::before {
            content: attr(class);
        }
        
        h1::after {
            content: attr(data-name);
        }
        /*动态提示框*/
        
        .hover-tips {
            position: relative;
            padding: 0 20px;
            border-radius: 10px;
            height: 40px;
            background-color: #66f;
            line-height: 40px;
            color: #fff;
        }
        
        .hover-tips {
            margin-top: 10px;
        }
        
        .btn-1::after {
            position: absolute;
            left: 0;
            top: 0;
            border-radius: 5px;
            width: 100%;
            height: 100%;
            background-color: #ff6666;
            opacity: 0;
            text-align: center;
            font-size: 12px;
            content: attr(data-msg);
            transition: all 300ms;
            z-index: 999;
        }
        
        .btn-1:hover::after {
            left: calc(100% + 120px);
            opacity: 1;
        }
        
        .btn-2:empty::after {
            content: attr(href);
        }
    </style>
</head>

<body>
    <h1 class="hello" data-name="玩转CSS的艺术之美"></h1>
    <a class="hover-tips btn-1" href="https://www.baidu.com" data-msg="Hello World">提示框</a><br />
    <a class="hover-tips btn-2" href="https://www.baidu.com"></a>
</body>

</html>